from pydantic import ConfigDict, Field
from typing_extensions import Self

from app.utils.decorators.optional import optional
from ..models.base import SQLBaseModel, IdType
from ..models.region import BaseRegion


class RegionCreate(BaseRegion):
    parent_id: IdType | None = Field(description="父级ID")


@optional(without_fields=["id"])
class RegionUpdate(RegionCreate):
    id: IdType = Field(description="ID")


class RegionOut(SQLBaseModel, RegionCreate):
    model_config = ConfigDict(from_attributes=True)

    parent_id: IdType | None = Field(description="父级ID")


class RegionTreeOut(SQLBaseModel, RegionCreate):
    model_config = ConfigDict(from_attributes=True)

    parent_id: IdType | None = Field(description="父级ID")
    children: list[Self] | None = Field(description="子级")

class RegionExport(RegionOut):
    model_config = ConfigDict(from_attributes=True)
